package com.rfsp.mcp.controller.bank;

import com.github.pagehelper.PageInfo;
import com.rfsp.common.base.ResultListVO;
import com.rfsp.common.log.TrcMsg;
import com.rfsp.common.shiro.ShiroUtils;
import com.rfsp.common.util.XssUtils;
import com.rfsp.common.pojo.po.UserPO;
import com.rfsp.common.pojo.sdto.PageSDTO;
import com.rfsp.mcp.pojo.sdto.ProductSDTO;
import com.rfsp.mcp.pojo.vo.OrderVo;
import com.rfsp.mcp.pojo.vo.ProductVO;
import com.rfsp.mcp.service.ProductService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@RequiresRoles(value={"mcp_bank"}, logical= Logical.AND)
@Controller("BankProductController")
@RequestMapping("/bank/product")
public class BankProductController extends BankController {

    public Logger logger = LoggerFactory.getLogger(BankProductController.class);

    @Autowired
    ProductService service;

    @RequestMapping("/")
    public String index1(ModelMap model, PageSDTO pageSdto, ProductSDTO sdto) {
        return index(model,pageSdto,sdto);
    }
    @RequestMapping("/index")
    public String index(ModelMap model, PageSDTO pageSdto, ProductSDTO sdto) {
        logger.info(TrcMsg.getMsg(TrcMsg.METHOD_END, "BankProductController.index"));

        sdto=XssUtils.replaceXss(sdto);

        OrderVo orderVo=new OrderVo("desc",sdto.getPublishTimeOrder(),sdto.getPublishTimeOrderSubmit(),2);
        sdto.setPublishTimeOrder(orderVo.getValue());
        sdto.setPublishTimeOrderSubmit(orderVo.getSubmitValue());

        UserPO currentUser = ShiroUtils.getCurrentUser();
        sdto.setBankOrgId(currentUser.getOrgId());
        sdto.setProductStatus("2");
        PageInfo<ProductVO> page=service.get(sdto,pageSdto);
//        service.combo(page.getList());
        ResultListVO<ProductVO> result = ResultListVO.success(page,sdto);
        model.put("vo", result);
        logger.info(TrcMsg.getMsg(TrcMsg.METHOD_END, "BankProductController.index"));
        return "bank/product/index";
    }
}